import {
  Resolver,
  Query,
  Mutation,
  Args,
  Int,
  ResolveField,
  Float,
  Parent,
} from '@nestjs/graphql';
import { PlayerModelDataService } from './player-model-data.service';
import { PlayerModelData } from './entities/player-model-datum.entity';

@Resolver(() => PlayerModelData)
export class PlayerModelDataResolver {
  constructor(
    private readonly playerModelDataService: PlayerModelDataService,
  ) {}

  @Query(() => [PlayerModelData], { name: 'playerModelDatas' })
  findAll() {
    return this.playerModelDataService.findAll();
  }

  @Query(() => PlayerModelData, { name: 'playerModelData' })
  findOne(@Args('id', { type: () => Int }) id: number) {
    return this.playerModelDataService.findOne(id);
  }

  @Mutation(() => PlayerModelData)
  removePlayerModelDatum(@Args('id', { type: () => Int }) id: number) {
    return this.playerModelDataService.remove(id);
  }

  @ResolveField(() => [Float])
  roles(@Parent() playerModelData: PlayerModelData) {
    const list = Array.from(playerModelData.roles.entries());
    return list.map(([key, value]) => ({
      key,
      value,
    }));
  }
}
